<?php

class PostAction extends CAction
{
    public function run()
    {
		$model=new Post;
		if(isset($_POST['Post']))
		{
			$model->attributes=$_POST['Post'];
			$uploadFile = CUploadedFile::getInstance($model, 'image_url');
			if($uploadFile !== null){
				$uploadFileName = time() . '.' . $uploadFile->getExtensionName();
				$model->image_url = $uploadFileName;
			}
			
			//$model->uid = $_SESSION['token']['uid'];
			$model->uid = 1;
			if($model->save()){
				$uploadFile->saveAs(Yii::app()->basePath . '/../upload/'.$uploadFileName);
				$this->controller->redirect(array('post/create'));
			}
		}
		
		$this->controller->render('/post/create',array(
			'model'=>$model,
		));
	}
}
?>